<?php

namespace app\web\controller;

use think\Controller;
use think\Db;
use think\Request;
use think\Session;
 
class RegisterController extends Controller
{
    public function index()
    {
        return view('index/regist');
    }


     public function save(Request $request)
    {
        $p = $request->post();
            // 手机验证
            $preg='/^1([358]\d|4[579]|66|7[0135678]|9[89])\d{8}$/';
            if( !preg_match($preg, $p['tel']) ){
                return $this->error('手机格式不符');
            }

            // 2 密码验证
            $preg='/^\S{6,14}$/';
            if( !preg_match($preg, $p['pass']) ){
                return $this->error('密码格式不正确');
            }

            // 2.2 相等删除加密的密码
            $p['pass'] = md5($p['pass']);
            $p['regtime'] = time();

            // $captcha=input('verify');

              $result = db('user')->data($p)->insert();
            // 判断 执行情况
            if ($result > 0) {
                return $this->success('注册成功！','web/LoginController/index');
            } else {
                return $this->error('注册失败！');
            }
    }
}
